package com.fastjars.error;

import org.apache.commons.util.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;

/**
 * GlobalExceptionController
 *
 * @author Brant Liu <br> 邮箱：<br>lbf1988@qq.com <br>日期：<br>2018/05/25
 * @version 1.0.0
 */
@Controller
public class GlobalExceptionController {
    @RequestMapping("403")
    public ModelAndView notPermissionPageError(String model) throws IOException {
        if(!StringUtils.isBlank(model) && "admin".equals(model)){
            return new ModelAndView("error/403");
        }
        return new ModelAndView("error/403");
    }

    @RequestMapping("404")
    public ModelAndView notFoundPageError(String model) throws IOException {
        if(!StringUtils.isBlank(model) && "admin".equals(model)){
            return new ModelAndView("error/404");
        }
        return new ModelAndView("error/404");
    }

    @RequestMapping("500")
    public ModelAndView systemError(String model) throws IOException {
        if(!StringUtils.isBlank(model) && "admin".equals(model)){
            return new ModelAndView("error/500");
        }
        return new ModelAndView("error/500");
    }

    @RequestMapping("error")
    public ModelAndView error() throws IOException {
        return new ModelAndView("error/error");
    }
}
